﻿
Imports System.IO
Imports System.IO.Ports
Imports System.Threading



Public Class Form1
    Shared _continue As Boolean
    Shared _serialPort As SerialPort

   


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Close()
        SerialPort1.PortName = "com3" 'change com port to match your Arduino port
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default 'very important!
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        SerialPort1.Open()
        SerialPort1.Write("0")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub



    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        SerialPort1.Open()
        SerialPort1.Write("1")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()

    End Sub


    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        SerialPort1.Open()
        SerialPort1.Write("2")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        SerialPort1.Open()
        SerialPort1.Write("3")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        SerialPort1.Open()
        SerialPort1.Write("4")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        SerialPort1.Open()
        SerialPort1.Write("5")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        SerialPort1.Open()
        SerialPort1.Write("6")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        SerialPort1.Open()
        SerialPort1.Write("7")
        System.Threading.Thread.Sleep(250)
        Dim i As String = SerialPort1.ReadExisting()
        TextBox1.Text = i
        SerialPort1.Close()
    End Sub

   

   
End Class